package com.juzhi.dvrapp.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.juzhi.dvrapp.R;
import com.juzhi.dvrapp.utils.MLog;
import com.juzhi.dvrapp.videoplay.listener.StandardVideoAllCallBack;
import com.juzhi.dvrapp.videoplay.video.StandardGSYVideoPlayer;
import com.juzhi.dvrapp.videoplay.video.base.GSYBaseVideoPlayer;

/**
 * 无任何控制ui的播放
 * Created by guoshuyu on 2017/8/6.
 */

public class EmptyControlVideo extends StandardGSYVideoPlayer implements StandardVideoAllCallBack {
    protected ImageView mCoverImage;

    protected String mUrl;

    protected int mDefaultRes;

    public EmptyControlVideo(Context context, Boolean fullFlag) {
        super(context, fullFlag);
        setStandardVideoAllCallBack(this);
    }

    public EmptyControlVideo(Context context) {
        super(context);
        setStandardVideoAllCallBack(this);
    }

    public EmptyControlVideo(Context context, AttributeSet attrs) {
        super(context, attrs);
        setStandardVideoAllCallBack(this);
    }

    @Override
    public int getLayoutId() {
        return R.layout.empty_control_video;
    }

    @Override
    protected void init(Context context) {
        super.init(context);
        mProgressBar.setEnabled(false);
        mCoverImage = (ImageView) findViewById(R.id.thumbImage);
    }

    @Override
    protected void touchSurfaceMoveFullLogic(float absDeltaX, float absDeltaY) {
        super.touchSurfaceMoveFullLogic(absDeltaX, absDeltaY);
        //不给触摸快进，如果需要，屏蔽下方代码即可
        mChangePosition = false;

        //不给触摸音量，如果需要，屏蔽下方代码即可
//        mChangeVolume = false;

        //不给触摸亮度，如果需要，屏蔽下方代码即可
//        mBrightness = false;
    }



    @Override
    protected void touchDoubleUp() {
        //super.touchDoubleUp();
        //不需要双击暂停
    }

    public void loadCoverImage(String url, int res) {
        mUrl = url;
        mDefaultRes = res;
        Glide.with(getContext().getApplicationContext())
                .setDefaultRequestOptions(
                        new RequestOptions()
                                .frame(1000000)
                                .centerCrop()
                                .error(res)
                                .placeholder(res))
                .load(url)
                .into(mCoverImage);
    }

    @Override
    public GSYBaseVideoPlayer startWindowFullscreen(final Context context, boolean actionBar, boolean statusBar) {
        GSYBaseVideoPlayer gsyBaseVideoPlayer = super.startWindowFullscreen(context, actionBar, statusBar);
        final EmptyControlVideo emptycontrolvideo = (EmptyControlVideo) gsyBaseVideoPlayer;
        emptycontrolvideo.loadCoverImage(mUrl, mDefaultRes);
        return gsyBaseVideoPlayer;
    }

    @Override
    public void onError(int what, int extra) {
        MLog.e("what===="+what+"-----extra====="+extra);   // what :   192 超时
        super.onError(what, extra);

    }

    @Override
    public void onPrepared(String url, Object... objects) {
        MLog.w("加载成功");
//        startWindowFullscreen(mContext,true,true);
    }

    @Override
    public void onClickStartIcon(String url, Object... objects) {
        MLog.w("点击了开始按键播放");
    }

    @Override
    public void onClickStartError(String url, Object... objects) {
        MLog.w("点击了错误状态下的开始按键");
    }

    @Override
    public void onClickStop(String url, Object... objects) {
        MLog.w("点击了播放状态下的开始按键");
    }

    @Override
    public void onClickStopFullscreen(String url, Object... objects) {
        MLog.w("点击了全屏播放状态下的开始按键");
    }

    @Override
    public void onClickResume(String url, Object... objects) {
        MLog.w("点击了暂停状态下的开始按键");
    }

    @Override
    public void onClickResumeFullscreen(String url, Object... objects) {
        MLog.w("点击了全屏暂停状态下的开始按键");
    }

    @Override
    public void onClickSeekbar(String url, Object... objects) {
        MLog.w("点击了空白弹出seekbar");
    }

    @Override
    public void onClickSeekbarFullscreen(String url, Object... objects) {
        MLog.w("点击了全屏的seekbar");
    }

    @Override
    public void onAutoComplete(String url, Object... objects) {
        MLog.w("播放完了");
    }

    @Override
    public void onEnterFullscreen(String url, Object... objects) {
        MLog.w("进去全屏");
    }

    @Override
    public void onQuitFullscreen(String url, Object... objects) {
        MLog.w("退出全屏");
    }

    @Override
    public void onQuitSmallWidget(String url, Object... objects) {
        MLog.w("进入小窗口");
    }

    @Override
    public void onEnterSmallWidget(String url, Object... objects) {
        MLog.w("退出小窗口");
    }

    @Override
    public void onTouchScreenSeekVolume(String url, Object... objects) {
        MLog.w("触摸调整声音");
    }

    @Override
    public void onTouchScreenSeekPosition(String url, Object... objects) {
        MLog.w("触摸调整进度");
    }

    @Override
    public void onTouchScreenSeekLight(String url, Object... objects) {
        MLog.w("触摸调整亮度");
    }

    @Override
    public void onPlayError(String url, Object... objects) {
         MLog.w("播放错误");
//        AppManager.getAppManager().finishActivity();
    }

    @Override
    public void onClickStartThumb(String url, Object... objects) {
        MLog.w("点击了空白区域开始播放");
    }

    @Override
    public void onClickBlank(String url, Object... objects) {
        MLog.w("点击了播放中的空白区域");
    }

    @Override
    public void onClickBlankFullscreen(String url, Object... objects) {
        MLog.w("点击了全屏播放中的空白区域");
    }

}
